package chenji.gunapi;

import java.io.File;
import java.util.logging.Logger;

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.injector.GamePhase;

import chenji.gunapi.gun.M4A1;
import chenji.gunapi.gun.M4A2;
import chenji.gunapi.gun.TestGun;
import chenji.gunapi.listeners.Listeners;
import chenji.gunapi.listeners.PListener;
import chenji.gunapi.listeners.Pliblistener;
import chenji.gunapi.pluginmessage.PluginMessageListeners;
import chenji.gunapi.pluginmessage.PluginMessageUntl;
import chenji.gunapi.untl.asm.AsmManager;

public class Main extends JavaPlugin {
	private static Plugin plugin;
	private static File datafolder;
	private static Logger log;

	public void onEnable() {
		ProtocolLibrary.getProtocolManager()
				.addPacketListener(new Pliblistener(PacketAdapter.params()
						.plugin(this)
						.serverSide()
						.gamePhase(GamePhase.PLAYING)
						.types(PacketType.Play.Server.SPAWN_ENTITY_LIVING)));
		Main.plugin = this;
		datafolder = this.getDataFolder();
		Bukkit.getPluginManager().registerEvents(new Listeners(), this);
		Bukkit.getMessenger().registerIncomingPluginChannel(this, "GunAPIClient", new PluginMessageListeners());
		Bukkit.getMessenger().registerOutgoingPluginChannel(this, "GunAPIClient");
		GunAPI.getGunAPI().loadManager();
		TestGun g = new TestGun();
		GunAPI.getGunAPI().getGunManager().addGun(g);
		GunAPI.getGunAPI();
		AsmManager.getAsmManager();
		GunAPI.getGunAPI().setKickWithoutMod(false);
		PluginMessageUntl.load();
		log = getLogger();
		new PListener();
		new M4A1();
		new M4A2();

	}

	public static Logger getLog() {
		return Main.log;
	}

	public static Plugin getPlugin() {
		return Main.plugin;
	}

	public void onDisable() {
		GunAPI.getGunAPI().getGunTaskManager().disable();
	}

	public static File getDataFold() {
		return Main.datafolder;
	}
}
